﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Nate_sRoguelikeGameXNA
{
    static class Extensions
    {
        public static void Draw(this Rectangle rectangle, SpriteBatch spriteBatch, char character, Color color)
        {
            Message message = new Message() { Text = character.ToString(), Color = color };
            for (int x = rectangle.Left; x <= rectangle.Right; x++)
                for (int y = rectangle.Top; y <= rectangle.Bottom; y++)
                    if (x == rectangle.Left || x == rectangle.Right || y == rectangle.Top || y == rectangle.Bottom)
                    {
                        message.Location = Game.GetScreenCoordsWithOffset(x, y);
                        message.Draw(spriteBatch);
                    }
        }

        /// <summary>
        /// Computes the area of the rectangle
        /// </summary>
        /// <param name="rectangle"></param>
        /// <returns></returns>
        public static int GetArea(this Rectangle rectangle)
        {
            return rectangle.Width * rectangle.Height;
        }

        /// <summary>
        /// Creates a rectangle defining the area where this rectangle overlaps the other rectangle
        /// </summary>
        /// <param name="rectangle"></param>
        /// <param name="otherRectangle"></param>
        /// <returns></returns>
        public static Rectangle Intersect(this Rectangle rectangle, Rectangle otherRectangle)
        {
            return Rectangle.Intersect(rectangle, otherRectangle);
        }

        /// <summary>
        /// Determines if the rectangle contains the point
        /// </summary>
        /// <param name="rectangle"></param>
        /// <param name="point"></param>
        /// <returns></returns>
        public static bool ReallyContains(this Rectangle rectangle, Point point)
        {
            bool result = (point.X >= rectangle.Left && point.X <= rectangle.Right
                        && point.Y >= rectangle.Top && point.Y <= rectangle.Bottom);
            return (point.X >= rectangle.Left && point.X <= rectangle.Right
                    && point.Y >= rectangle.Top && point.Y <= rectangle.Bottom);
        }

        /// <summary>
        /// Computes the distance between two points
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        /// <returns></returns>
        public static double Distance (this Point p1, Point p2)
        {
            return Math.Sqrt(Math.Pow(p2.X - p1.X, 2) - Math.Pow(p2.Y - p1.Y, 2));
        }

    }
}
